package com.kangrui.lucene.pinyin;

import java.util.Map;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.util.TokenFilterFactory;

public class PinyinNGramTokenFilterFactory extends TokenFilterFactory {

	private int minPos;
	private int maxPos;

	public PinyinNGramTokenFilterFactory(Map<String, String> args) {
		super(args);
		this.minPos = getInt(args, "minPos", 0);
		this.maxPos = getInt(args, "maxPos", 0);
		if (!args.isEmpty()) {
			throw new IllegalArgumentException("Unknown parameters: " + args);
	    }
	}

	@Override
	public TokenStream create(TokenStream input) {
		if(minPos==0&&maxPos==0)
			return new PinyinNGramTokenFilter(input);
		else 
			return new PinyinNGramTokenFilter(input, minPos, maxPos);
	}
	
}
